﻿using FTBS.Models.BLO;
using FTBS.Models.Entities;
using FTBS.Models.Entities.Concert;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FTBS.Controllers
{
    public class ShowTimeController : Controller
    {
        private ShowTimeBLO _showTimeBLO = new ShowTimeBLO();
        private TheaterBLO _theaterBLO = new TheaterBLO();

        /// <summary>
        /// Load all showtime into table 
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            ViewBag.Count = 0;
            List<ShowTimeConcertEntity> listShowTime = new List<ShowTimeConcertEntity>();
            listShowTime = _showTimeBLO.GetAllShowTime();
            return View(listShowTime);
        }

        /// <summary>
        /// Load page create
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>VuongVT</author>
        /// <date>3/8/2014</date>
        public ActionResult CreateShowTime()
        {
            ViewBag.CurrentDay = DateTime.Now.Date;
            ViewBag.Hours = _showTimeBLO.ListHours();
            ViewBag.Minutes = _showTimeBLO.ListMinutes();
            ViewBag.Theater = new SelectList(_theaterBLO.GetAllTheaterInfo(), "TheaterId", "TheaterName");
            return View();
        }

        /// <summary>
        /// Create a schedule film
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        /// <author>vuongvt</author>
        /// <date>3/3/2014</date>
        [HttpPost]
        public ActionResult CreateShowTime(ShowTime showtime)
        {
            if (ModelState.IsValid)
            {
                _showTimeBLO.CreateShowTime(showtime);
                return RedirectToAction("Index");
            }
            else
            {
                ViewBag.Hours = _showTimeBLO.ListHours();
                ViewBag.Minutes = _showTimeBLO.ListMinutes();
                ViewBag.Theater = new SelectList(_theaterBLO.GetAllTheaterInfo(), "TheaterId", "TheaterName", showtime.TheaterId);

                return View(showtime);
            }
        }

        /// <summary>
        /// Load object ShowTime by ShowTimeId
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>VuongVT</author>
        /// <date>3/8/2014</date>
        public ActionResult EditShowTime(int id = 0)
        {
            ShowTime showTime = _showTimeBLO.GetShowTimeById(id);
            if (showTime == null)
            {
                return HttpNotFound();
            }
            ViewBag.Theater = new SelectList(_theaterBLO.GetAllTheaterInfo(), "TheaterId", "TheaterName", showTime.TheaterId);
            return View(showTime);
        }

        /// <summary>
        /// Edit ShowTime Information
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        /// <author>VuongVT</author>
        /// <date>3/8/2014</date>
        [HttpPost]
        public ActionResult EditShowTime(ShowTime showTime)
        {
            if (ModelState.IsValid)
            {
                _showTimeBLO.EditShowTime(showTime);
                return RedirectToAction("Index");
            }
            ViewBag.Theater = new SelectList(_theaterBLO.GetAllTheaterInfo(), "TheaterId", "TheaterName", showTime.TheaterId);
            return View(showTime);
        }

        /// <summary>
        /// Delete a showtime
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>hungph</author>
        /// <date>3/3/2014</date>
        [HttpDelete, ActionName("DeleteShowTime")]
        public ActionResult DeleteShowTime(int id = 0)
        {
            ShowTime showtime = _showTimeBLO.GetShowTimeById(id);
            if (showtime == null)
            {
                return HttpNotFound();
            }
            _showTimeBLO.DeleteShowTime(showtime);
            return RedirectToAction("Index");
        }
    }
}
